package com.eos.inter.servlet;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eos.common.tool.DaoAccessObjectPoolContextFactory;
import com.eos.orm.mybatis.dao.DelayCustDailyReportMapper;
import com.eos.orm.mybatis.model.DelayCustDailyReport;
import com.hf.utils.StringUtil;

/**
 * 逾期客户每日报表（每日提供，昨日数据）接口
 * 
 * @author sz
 * 
 */
public class DelayCustDailyReportBackServlet extends BaseHttpServlet {

	private static final long serialVersionUID = 1L;
	private DelayCustDailyReportMapper mapper = (DelayCustDailyReportMapper) DaoAccessObjectPoolContextFactory
			.getInstaAccessObjectPoolContext().instanceDataAccessObject(
					"DelayCustDailyReportMapper");

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		DelayCustDailyReport delayCustDailyReportBack = new DelayCustDailyReport();// 添加数据的对象
		delayCustDailyReportBack.setCustomerId(StringUtil.parseInt(StringUtil
				.NullToString(request.getParameter("customer_id"))));// 区分哪个结算客户
		delayCustDailyReportBack.setPartnerName(StringUtil.NullToString(request
				.getParameter("parnter_name")));//
		delayCustDailyReportBack.setCustName(StringUtil.NullToString(request
				.getParameter("cust_name")));//
		delayCustDailyReportBack.setCustAlipayAccount(StringUtil
				.NullToString(request.getParameter("cust_alipay_account")));
		delayCustDailyReportBack.setCustIdCard(StringUtil.NullToString(request
				.getParameter("cust_id_card")));
		delayCustDailyReportBack.setCustAlipayAccountId(StringUtil
				.NullToString(request.getParameter("cust_alipay_account_id")));
		delayCustDailyReportBack.setTaobaoOrderId(StringUtil
				.NullToString(request.getParameter("taobao_order_id")));
		delayCustDailyReportBack.setCustSelfPhone(request.getParameter("cust_self_phone"));
		delayCustDailyReportBack.setCustContractPhone(StringUtil
				.NullToString(request.getParameter("cust_contract_phone")));
		delayCustDailyReportBack.setContractPhoneType(request.getParameter("contract_phone_type"));
		delayCustDailyReportBack.setCustCity(request.getParameter("cust_city"));
		delayCustDailyReportBack.setPackageTotalAmount(StringUtil
				.NullToString(request.getParameter("package_total_amount")));
		delayCustDailyReportBack.setPackageType(StringUtil.NullToString(request
				.getParameter("package_type")));
		delayCustDailyReportBack.setPackageTotalAmount(StringUtil
				.NullToString(request.getParameter("package_total_amount")));
		delayCustDailyReportBack.setBillTotalFee(StringUtil
				.NullToString(request.getParameter("bill_total_fee")));
		delayCustDailyReportBack.setBillDelayFee(StringUtil
				.NullToString(request.getParameter("bill_delay_fee")));
		delayCustDailyReportBack.setBillPayableFee(StringUtil
				.NullToString(request.getParameter("bill_payable_fee")));
		delayCustDailyReportBack.setContractOrderDate(StringUtil
				.NullToString(request.getParameter("contract_order_date")));
		delayCustDailyReportBack.setBillDelayDays(StringUtil
				.NullToString(request.getParameter("bill_delay_days")));
		delayCustDailyReportBack.setIsNewDelay(StringUtil.NullToString(request
				.getParameter("is_new_delay")));
		delayCustDailyReportBack.setReportDate(StringUtil.NullToString(request
				.getParameter("report_date")));
		delayCustDailyReportBack.setInsertTime(StringUtil
				.stringDate(new Date()));
		delayCustDailyReportBack.setStatus("0");

		ServletOutputStream out = null;
		try {
			out = response.getOutputStream();
			if (identification(delayCustDailyReportBack.getCustContractPhone(),
					delayCustDailyReportBack.getCustIdCard())) {
				// 失败返回1
				out.write("1".toString().getBytes("utf-8"));
				return ;
			}
			if (0 != delayCustDailyReportBack.getCustomerId()
					&& mapper.insert(delayCustDailyReportBack) == 0) {
				// 成功返回0
				out.write("0".toString().getBytes("utf-8"));
			} else {
				// 失败返回1
				out.write("1".toString().getBytes("utf-8"));
			}
		} catch (Exception e) {
			log
					.error("com.eos.inter.servlet.DelayCustDailyReportBackServlet.doPost throws exception:"
							+ e.getMessage());
		} finally {
			if (null != out) {
				out.flush();
				out.close();
			}
		}
	}
}
